package com.he.architecture.service;

import com.he.architecture.common.service.LogicService;
import com.he.architecture.dao.ItemDao;
import com.he.architecture.dao.ShopDao;
import com.he.architecture.dao.ShopItemDao;
import com.he.architecture.dto.ShopWithItemResponseDto;
import com.he.architecture.entity.Item;
import com.he.architecture.entity.Shop;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class ItemService extends LogicService<ItemDao, Item,Long> {
    @Resource
    ShopService shopService;
    @Resource
    ModelMapper modelMapper;
    /**
     * 默认构造器
     */
    public ItemService(@Autowired ItemDao ud) {
        super(ud);
    }

    /**
     * 根据门店id获取订单
     */
    public List<ShopWithItemResponseDto> getItemsByShopIds(List<Long> shop_ids){

        List<ShopWithItemResponseDto> reses=new ArrayList<>();
        for (Long shopId : shop_ids) {
            ShopWithItemResponseDto responseDto=new ShopWithItemResponseDto();
            List<Item> items= getDAO().getItemsByShopId(shopId);
            Shop shop=shopService.GET(shopId);
            responseDto.setId(shop.getId());
            responseDto.setShopName(shop.getShopName());
            responseDto.setCreateTime(shop.getCreateTime());
            responseDto.setUpdateTime(shop.getUpdateTime());
            responseDto.setItems(items);
            reses.add(responseDto);

        }
        return reses;
    }
    public List<Item> getItemsByShopId(Long shop_id){
       return getDAO().getItemsByShopId(shop_id);
    }
}
